<?php
namespace Home\Controller;

use Think\Controller;

class HomeController extends Controller
{
    /**
     * 微信端前台控制器初始化操作
     * @return bool
     */
    public function _initialize(){
        //读取数据库中的配置
        $config     =   '';//S("DB_CONFIG");
        if(!$config){
            $Config     =   new \Common\Tool\Config();
            $config =   $Config::lists();//解析的配置数据
            S('DB_CONFIG',$config);
        }
        C($config);

        //判断是否是微信端
        if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
            trace("微信端");
        }else{
            trace("非微信端");
            if ( !C('PC_ALLOW') ){
                echo
                <<<'EOF'
<div style="margin-top: 50px;text-align: center;"><p style="display: inline;">请关注微信公众号：</p><h2 style="display: inline;">圣雪山葡萄酒</h2></div>
EOF;

                exit;
            }
            return false;
        }

        trace(session("member.id"),'uid');
        if($user_id = session('member.id')){
            $Cart = D("Cart");
            $cart_number = $Cart->where("user_id={$user_id} AND status=0")->count();
            $this->assign('cart_number',$cart_number);
        }

        //底部菜单
        $menus   =   array(
            array(
                'href'      =>  '/',
                'li_class'  =>  'padding-l margin-r',
                'src'       =>  C('TMPL_PARSE_STRING')['__IMG__'].'/menu-1.png',
                'p_class'   =>  '',
                'text'      =>  '首页'
            ),
            array(
                'href'      =>  U('Cate/index'),
                'li_class'  =>  'margin-r',
                'src'       =>  C('TMPL_PARSE_STRING')['__IMG__'].'/menu-2.png',
                'p_class'   =>  '',
                'text'      =>  '分类'
            ),
            array(
                'href'      =>  U('/Cart/index'),
                'li_class'  =>  'margin-r',
                'src'       =>  C('TMPL_PARSE_STRING')['__IMG__'].'/menu-3.png',
                'p_class'   =>  '',
                'text'      =>  '购物车'
            ),
            array(
                'href'      =>  U('/Center/index'),
                'li_class'  =>  'margin-r',
                'src'       =>  C('TMPL_PARSE_STRING')['__IMG__'].'/menu-4.png',
                'p_class'   =>  '',
                'text'      =>  '我的'
            ),
        );
        C("MENUS",$menus);


 
        $this->assign("CONTROLLER_NAME",CONTROLLER_NAME);
        $this->assign("ACTION_NAME",ACTION_NAME);

    }
}
